package com.asb.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.asb.model.PeopleInfo;
import com.asb.model.vo.ResultVo;
import com.asb.model.vo.UserVo;
import com.asb.service.PeopleService;
import com.asb.service.UserDingTalkService;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.json.FastJson;

import cn.hutool.json.JSONUtil;

/**
 * 处理业务工单中 执行人 抄送人 审核人 的选择相关业务
 * 
 * @author lenovo
 * @create 2022/3/21 14:16
 */
@Path("/dingtalk/inner/people")
@EnableCORS
public class PeopleController extends Controller {

	@Inject
	PeopleService peopleService;

	@Inject
	UserDingTalkService userService;

	// 通过手机号获取用户信息信息列表
	public void listByPhone() {
		String json = getRawData();
		PeopleInfo peopleInfo = FastJson.getJson().parse(json, PeopleInfo.class);
		Map<String, Object> result = new HashMap<>();
		if (null == peopleInfo || null == peopleInfo.getMobile() || peopleInfo.getMobile().size() == 0) {
			result.put("code", "400");
			result.put("msg", "请输入手机号");
			this.renderJson(result);
		}
		List<Map<String, Object>> peopleInfolist = peopleService.getPeopleInfoByPhone(peopleInfo);
		result.put("code", "200");
		result.put("msg", "成功");
		result.put("data", peopleInfolist);
		this.renderJson(result);
	}

	// 通过钉钉IDS获取用户信息列表
	public void list() {

		String userid = this.getPara("userid");
		String userStr = userService.getUserDetail(userid);
		String phone = JSONUtil.parseObj(userStr).getJSONObject("result").getStr("mobile");
		List<UserVo> uList = peopleService.getPeopleInfoByPhone(phone);
		this.renderJson(new ResultVo<List<UserVo>>().setData(uList));

	}

}
